package com.cj.common.web.struts2;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.cj.common.security.springsecurity.SpringSecurityUtils;
import com.cj.sys.vo.Message;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BaseActionSupport extends ActionSupport {
	/** 系统错误信息 */
	private String errMessage;
	private String errMessage_more;
	private String currentUserName;
	public static final String OK = "ok";
	/** 系统返回信息 */
	private String message;
	/** 批量处理返回的信息 */
	private List<Message> messages;

	public List<Message> getMessages() {
		return messages;
	}

	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}


	public void setErrMessage(String errMessage) {
		this.errMessage = errMessage;
	}
	
	
	public String getErrMessage() {
		return errMessage;
	}


	public String getErrMessage_more() {
		return errMessage_more;
	}

	public void setErrMessage_more(String errMessage_more) {
		this.errMessage_more = errMessage_more;
	}

	public void setErrMessage(String errMessage, Exception e) {
		errMessage_more = e.getMessage();
		errMessage_more += "<br> 错误来源:";
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		try {
			e.printStackTrace(pw);
			errMessage_more += sw.toString();
			sw.close();
			pw.close();
		} catch (Exception ee) {
		}
		this.setErrMessage("错误信息:" + errMessage);
	}	
	
	public String getCurrentUserName() {
		if (currentUserName == null) {
			currentUserName = SpringSecurityUtils.getCurrentUserName();
		}
		return currentUserName;
	}

	public HttpServletRequest getWWRequest() {
		return ServletActionContext.getRequest();
	}
	
	/**
	 * Convenience method to get the session
	 */
	public HttpSession getWWSession() {
		return getWWRequest().getSession();
	}
}
